#include "gpio_x.h"

#define AMP_EN_PIN GPIO_NUM_11
#define LED_PIN GPIO_NUM_23
// #define GPIO_OUPUT_PIN_SEL (1UL << LED_PIN)

void btn_init(gpio_num_t gpio_num){

    assert(GPIO_IS_VALID_GPIO(gpio_num));
    gpio_config_t io_conf = {
        .pin_bit_mask = BIT64(gpio_num),
        .mode = GPIO_MODE_DISABLE,
        //for powersave reasons, the GPIO should not be floating, select pullup
        .pull_up_en = true,
        .pull_down_en = false,
        .intr_type = GPIO_INTR_DISABLE,
    };    //default setting, coppied from gpio_reset_pin()

    // change some as your need
    //interrupt of falling edge
    io_conf.intr_type = GPIO_INTR_NEGEDGE;
    //set as input mode
    io_conf.mode = GPIO_MODE_INPUT;
    //enable pull-up mode
    io_conf.pull_up_en = 1;
    gpio_config(&io_conf);
}

int get_btn_level(gpio_num_t gpio_num){
    return gpio_get_level(gpio_num);
}

void gpio_init(){
    gpio_config_t io_conf = {
        .pin_bit_mask = (1ULL<<AMP_EN_PIN),
        .mode = GPIO_MODE_DISABLE,
        //for powersave reasons, the GPIO should not be floating, select pullup
        .pull_up_en = true,
        .pull_down_en = false,
        .intr_type = GPIO_INTR_DISABLE,
    };    //default setting, coppied from gpio_reset_pin()

    // change some as your need
    io_conf.mode = GPIO_MODE_INPUT_OUTPUT;
    //enable pull-up mode
    io_conf.pull_down_en = true;
    gpio_config(&io_conf);
}


void amp_enable(void){
    gpio_set_level(AMP_EN_PIN,1);
}

void amp_disable(void){
    gpio_set_level(AMP_EN_PIN,0);
}


void led_init(void){
        gpio_config_t io_conf = {
        .pin_bit_mask = (1UL << LED_PIN),
        .mode = GPIO_MODE_INPUT_OUTPUT,
        .intr_type = GPIO_INTR_DISABLE,
        .pull_down_en = 0,
        .pull_up_en = 0};
    gpio_config(&io_conf);
}

int get_led_state(void){
    return gpio_get_level(LED_PIN);
}

void set_led_level(int i){
    gpio_set_level(LED_PIN,i);
}


void led_toggle(void){
    set_led_level(1-get_led_state());    
}